package com.example.myapplication.util;

import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;

import com.example.myapplication.LoginPage;

/**
 * Created by Administrator on 2020/12/7.
 */
//sp工具类
public class saveSoul {
    private Context context;

    public saveSoul(Context context){
        this.context = context;
    }




    //用户登录时，根据用户输入的用户姓名学号，查询数据库是否存在
    //select *from account where username=”“ and student_id=""
    public boolean loginSelect(String username,String password){

        MyHelper myHelper = new MyHelper(context);
        SQLiteDatabase db = myHelper.getReadableDatabase();
        Cursor cursor = db.rawQuery("select *from account where username=? and password=?",new String[]{username,password});
        if(cursor.getCount() != 0){
            return true;
        }else {
            return false;
        }

    }

    //注册
    //insert into account(username,student_id) value(?,?);
    public boolean signInInsert(String username,String password){

        MyHelper myHelper = new MyHelper(context);
        SQLiteDatabase db = myHelper.getWritableDatabase();
        db.execSQL("insert into account(username,password) values(?,?)",new Object[]{username,password});
        return true;
    }



    //注册
    //insert into account(username,student_id) value(?,?);
    public boolean getSaveString(String username, String password){

        MyHelper myHelper = new MyHelper(context);
        SQLiteDatabase db = myHelper.getWritableDatabase();
        db.execSQL("insert into account(username,password) values(?,?)",new Object[]{username,password});
        return true;
    }

}